/**
 * Author: Shen Yanqiu
 * Date: 2018-02-27
 * Time: 17:48
 *
 */
import modelExtend from 'dva-model-extend';
import {pageModel} from '../../common';
import {message} from 'antd';
import { delay, routerTool } from "utils";

export default modelExtend(pageModel, {
  namespace: 'newmediaStatisticsCartogram',
  state: {
    tabsKey: 'weibo',
    areaChartDateWeiBoFSZS: [],
    areaChartDateWeiBoYDLZS: [],
    areaChartDateWeiBoDZZS: [],
    areaChartDateWeiBoPLZS: [],
    areaChartDateWeiBoZFZS: [],
    areaChartDateWeixinFSZS: [],
    areaChartDateWeixinYDLZS: [],
    areaChartDateWeixinDZZS: [],
    areaChartDateWeixinPLZS: [],
    areaChartDateWeixinZFZS: [],
  },
  subscriptions: {
    setup ({ dispatch, history }) {
      history.listen((location) => {
        if (location.pathname === routerTool.getPathByName("NewMediaStatistics")) {
          dispatch({ type: 'firstLoad' });
        }
      });
    },
  },
  effects: {
    * firstLoad ({ payload = {} }, { put, call, select }) {
      yield put({
        type: 'loadDataList',
        payload: {
          tabsKey: 'weibo',
        },
      });
      yield delay(1000);
    },
    * changeTabs ({ payload: { key } }, { put, call }) {
      yield put({
        type: 'loadDataList',
        payload: {
          tabsKey: key,
        },
      });
    },
    * loadDataList ({ payload: { tabsKey } }, { put, call }) {
      if (tabsKey === 'weibo') {
        console.log(11111);
        const areaChartDateWeiBoFSZS = [
          {name: '10-23周日', uv: 10, time: '2012-12-01 02:21'},
          {name: '10-24周一', uv: 20, time: '2012-12-01 02:22'},
          {name: '10-25周二', uv: 15, time: '2012-12-01 02:23'},
          {name: '10-26周三', uv: 50, time: '2012-12-01 02:24'},
          {name: '10-27周四', uv: 20, time: '2012-12-01 02:25'},
          {name: '10-28周五', uv: 15, time: '2012-12-01 02:26'},
          {name: '10-29周六', uv: 30, time: '2012-12-01 02:27'},
          {name: '10-30周日', uv: 10, time: '2012-12-01 02:28'},
          {name: '10-31周一', uv: 20, time: '2012-12-01 02:29'},
          {name: '11-01周二', uv: 15, time: '2012-12-01 02:30'},
          {name: '11-02周三', uv: 40, time: '2012-12-01 02:31'},
          {name: '11-03周四', uv: 10, time: '2012-12-01 02:32'},
          {name: '11-04周五', uv: 5, time: '2012-12-01 02:33'},
          {name: '11-04周六', uv: 1, time: '2012-12-01 02:22'},
          {name: '10-23周日', uv: 10, time: '2012-12-01 02:22'},
          {name: '10-24周一', uv: 8, time: '2012-12-01 02:22'},
          {name: '10-25周二', uv: 15, time: '2012-12-01 02:22'},
          {name: '10-26周三', uv: 12, time: '2012-12-01 02:22'},
          {name: '10-27周四', uv: 10, time: '2012-12-01 02:22'},
          {name: '10-28周五', uv: 15, time: '2012-12-01 02:22'},
          {name: '10-29周六', uv: 12, time: '2012-12-01 02:22'},
          {name: '10-30周日', uv: 2, time: '2012-12-01 02:22'},
          {name: '10-31周一', uv: 21, time: '2012-12-01 02:22'},
          {name: '11-01周二', uv: 31, time: '2012-12-01 02:22'},
          {name: '11-02周三', uv: 20, time: '2012-12-01 02:22'},
        ];
        yield put({
          type: 'updateAreaChartDateWeiBoFSZS',
          payload: {
            areaChartDateWeiBoFSZS,
          },
        });
        yield put({
          type: 'updateAreaChartDateWeiBoYDLZS',
          payload: {
            areaChartDateWeiBoYDLZS: areaChartDateWeiBoFSZS,
          },
        });
        yield put({
          type: 'updateAreaChartDateWeiBoDZZS',
          payload: {
            areaChartDateWeiBoDZZS: areaChartDateWeiBoFSZS,
          },
        });
        yield put({
          type: 'updateAreaChartDateWeiBoPLZS',
          payload: {
            areaChartDateWeiBoPLZS: areaChartDateWeiBoFSZS,
          },
        });
        yield put({
          type: 'updateAreaChartDateWeiBoZFZS',
          payload: {
            areaChartDateWeiBoZFZS: areaChartDateWeiBoFSZS,
          },
        });
      } else if (tabsKey === 'weixin') {
        console.log(222);
        const areaChartDateWeixinFSZS = [
          {name: '10-23周日', uv: 10, time: '2012-12-01 02:21'},
          {name: '10-24周一', uv: 20, time: '2012-12-01 02:22'},
          {name: '10-25周二', uv: 15, time: '2012-12-01 02:23'},
          {name: '10-26周三', uv: 10, time: '2012-12-01 02:24'},
          {name: '10-27周四', uv: 80, time: '2012-12-01 02:25'},
          {name: '10-28周五', uv: 5, time: '2012-12-01 02:26'},
          {name: '10-29周六', uv: 30, time: '2012-12-01 02:27'},
          {name: '10-30周日', uv: 10, time: '2012-12-01 02:28'},
          {name: '10-31周一', uv: 20, time: '2012-12-01 02:29'},
          {name: '11-01周二', uv: 15, time: '2012-12-01 02:30'},
          {name: '11-02周三', uv: 40, time: '2012-12-01 02:31'},
          {name: '11-03周四', uv: 10, time: '2012-12-01 02:32'},
          {name: '11-04周五', uv: 51, time: '2012-12-01 02:33'},
          {name: '11-04周六', uv: 11, time: '2012-12-01 02:22'},
          {name: '10-23周日', uv: 10, time: '2012-12-01 02:22'},
          {name: '10-24周一', uv: 8, time: '2012-12-01 02:22'},
          {name: '10-25周二', uv: 15, time: '2012-12-01 02:22'},
          {name: '10-26周三', uv: 12, time: '2012-12-01 02:22'},
          {name: '10-27周四', uv: 20, time: '2012-12-01 02:22'},
          {name: '10-28周五', uv: 15, time: '2012-12-01 02:22'},
          {name: '10-29周六', uv: 92, time: '2012-12-01 02:22'},
          {name: '10-30周日', uv: 24, time: '2012-12-01 02:22'},
          {name: '10-31周一', uv: 61, time: '2012-12-01 02:22'},
          {name: '11-01周二', uv: 31, time: '2012-12-01 02:22'},
          {name: '11-02周三', uv: 90, time: '2012-12-01 02:22'},
        ];
        yield put({
          type: 'updateAreaChartDateWeixinFSZS',
          payload: {
            areaChartDateWeixinFSZS,
          },
        });
        yield put({
          type: 'updateAreaChartDateWeixinYDLZS',
          payload: {
            areaChartDateWeixinYDLZS: areaChartDateWeixinFSZS,
          },
        });
        yield put({
          type: 'updateAreaChartDateWeixinDZZS',
          payload: {
            areaChartDateWeixinDZZS: areaChartDateWeixinFSZS,
          },
        });
        yield put({
          type: 'updateAreaChartDateWeixinPLZS',
          payload: {
            areaChartDateWeixinPLZS: areaChartDateWeixinFSZS,
          },
        });
        yield put({
          type: 'updateAreaChartDateWeixinZFZS',
          payload: {
            areaChartDateWeixinZFZS: areaChartDateWeixinFSZS,
          },
        });
      }
    },
    * loadAreaChartWeiBoDate ({ payload: { checkTime, zsType } }, { put, call }) {
      console.log("weibo");
      console.log(checkTime);
      console.log(zsType);
    },
    * loadAreaChartWeixinDate ({ payload: { checkTime, zsType } }, { put, call }) {
      console.log("weixin");
      console.log(checkTime);
      console.log(zsType);
    },
    * bindAccount ({ payload: { values, typeName } }, { put, call }) {
      console.log(values);
      console.log(typeName);
      yield delay(1000);
    },
  },
  reducers: {
    updateTabsKey (state, { payload: { tabsKey } }) {
      return { ...state, ...{ tabsKey } };
    },
    updateAreaChartDateWeiBoFSZS (state, { payload: { areaChartDateWeiBoFSZS } }) {
      return { ...state, ...{ areaChartDateWeiBoFSZS } };
    },
    updateAreaChartDateWeiBoYDLZS (state, { payload: { areaChartDateWeiBoYDLZS } }) {
      return { ...state, ...{ areaChartDateWeiBoYDLZS } };
    },
    updateAreaChartDateWeiBoDZZS (state, { payload: { areaChartDateWeiBoDZZS } }) {
      return { ...state, ...{ areaChartDateWeiBoDZZS } };
    },
    updateAreaChartDateWeiBoPLZS (state, { payload: { areaChartDateWeiBoPLZS } }) {
      return { ...state, ...{ areaChartDateWeiBoPLZS } };
    },
    updateAreaChartDateWeiBoZFZS (state, { payload: { areaChartDateWeiBoZFZS } }) {
      return { ...state, ...{ areaChartDateWeiBoZFZS } };
    },
    updateAreaChartDateWeixinFSZS (state, { payload: { areaChartDateWeixinFSZS } }) {
      return { ...state, ...{ areaChartDateWeixinFSZS } };
    },
    updateAreaChartDateWeixinYDLZS (state, { payload: { areaChartDateWeixinYDLZS } }) {
      return { ...state, ...{ areaChartDateWeixinYDLZS } };
    },
    updateAreaChartDateWeixinDZZS (state, { payload: { areaChartDateWeixinDZZS } }) {
      return { ...state, ...{ areaChartDateWeixinDZZS } };
    },
    updateAreaChartDateWeixinPLZS (state, { payload: { areaChartDateWeixinPLZS } }) {
      return { ...state, ...{ areaChartDateWeixinPLZS } };
    },
    updateAreaChartDateWeixinZFZS (state, { payload: { areaChartDateWeixinZFZS } }) {
      return { ...state, ...{ areaChartDateWeixinZFZS } };
    },
  },
});
